<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"   pageEncoding="ISO-8859-1"%>
<%@ include file="global.jsp" %>
<%
	boolean validUser = false;
	try{
		
		String userName = request.getParameter("loginUserName");
		String password = request.getParameter("loginPassword");
		session.setAttribute("parameter" , null);
		System.out.println("userName ::" +userName);
		Class.forName(db_driver);
		Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
        Statement stmt = conn.createStatement();
        PreparedStatement pstmt = null;
        System.out.println("STARTED");
		String str = "select userName, league from users where userName = '"+userName+"' and password = '"+password+"'" ;
		System.out.println("SQL: "+str);
		ResultSet rset = stmt.executeQuery(str);
		while (rset.next()){
			validUser = true;
			System.out.println("validUser : league =" + rset.getString(1) +":"+ rset.getString(2));
			userName = rset.getString(1);
			String league = rset.getString(2);
			session.setAttribute("userName",userName);
			session.setAttribute("league",league);
		}
		if(!validUser){
			session.setAttribute("errorMesg","Invalid login credentials");
		}
		rset.close();
		stmt.close();
        conn.close();
	}
 	catch ( Exception e1){
		e1.printStackTrace();
		session.setAttribute("error",e1.getMessage());
	} 
	finally{
		
	}				
    if(validUser){
    	%>
    		<jsp:forward   page="matchSelect.jsp"/>
    	<%
    }else{
    	%>
			<jsp:forward   page="login.jsp"/>
		<%
    }
	%>

